//
//  LZUserInfoView.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/11/24.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZUserInfoView.h"
#import "Masonry.h"
#import "HCSStarRatingView.h"

@implementation LZUserInfoView

- (instancetype)init{
    
    self = [super init];
    if (self) {
        [self configView];
        [self addAutoLayout];
    }
    return self;
}

- (void)setCollectNum:(NSString*)aCollectNum andCommentNum:(NSString*)aCommentNum {
    self.collectNum.text = aCollectNum;
    self.commentNum.text = aCommentNum;
    
    [self.collectImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo((CGRectGetWidth(self.collectView.bounds)-10-5-self.collectNum.intrinsicContentSize.width)/2.0);
    }];
    
    [self.commentImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo((CGRectGetWidth(self.commentView.bounds)-10-5-self.commentNum.intrinsicContentSize.width)/2.0);
    }];
}

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    [self.collectImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo((CGRectGetWidth(self.collectView.bounds)-10-5-self.collectNum.intrinsicContentSize.width)/2.0);
    }];
    
    [self.commentImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo((CGRectGetWidth(self.commentView.bounds)-10-5-self.commentNum.intrinsicContentSize.width)/2.0);
    }];
}

- (void)configView {
    
    self.backgroundColor = UIColorFromRGB(0xffffff, 1);
    
    [self addSubview:self.headImageView];
    [self addSubview:self.starRatingView];
    [self addSubview:self.infoLabel];
    [self addSubview:self.collectView];
    [self.collectView addSubview:self.collectImage];
    [self.collectView addSubview:self.collectNum];
    
    [self addSubview:self.commentView];
    [self.commentView addSubview:self.commentImage];
    [self.commentView addSubview:self.commentNum];
}

- (void)addAutoLayout {
    
    WS(weakSelf);
    
    [self.headImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(-25);
        make.leading.mas_equalTo(15);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    
    [self.starRatingView makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.leading.mas_equalTo(weakSelf.headImageView.mas_trailing).with.offset(10);
        make.height.mas_lessThanOrEqualTo(15);
        make.width.mas_lessThanOrEqualTo(80);
    }];
    
    [self.infoLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.centerY);
        make.leading.mas_equalTo(15);
        make.trailing.mas_equalTo(-15);
        make.height.mas_equalTo(20);
    }];
    
    [self.collectView makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(weakSelf.infoLabel.mas_centerX).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(60, 15));
        make.top.mas_equalTo(weakSelf.infoLabel.mas_bottom).with.offset(10);
    }];
    
    [self.collectImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.collectView.centerY);
        make.leading.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    [self.collectNum makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.collectView.centerY);
        make.leading.mas_equalTo(weakSelf.collectImage.mas_trailing).with.offset(5);
        make.trailing.mas_lessThanOrEqualTo(-10);
    }];
    
    [self.commentView makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(weakSelf.infoLabel.mas_centerX).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(60, 15));
        make.top.mas_equalTo(weakSelf.infoLabel.mas_bottom).with.offset(10);
    }];
    
    [self.commentImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.commentView.centerY);
        make.leading.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    [self.commentNum makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.commentView.centerY);
        make.leading.mas_equalTo(weakSelf.commentImage.mas_trailing).with.offset(5);
        make.trailing.mas_lessThanOrEqualTo(-10);
    }];
}

- (UIImageView *)headImageView {
    
    if (_headImageView == nil) {
        _headImageView = [[UIImageView alloc] init];
        _headImageView.layer.masksToBounds = YES;
        _headImageView.layer.cornerRadius = 50/2.0;
    }
    
    return _headImageView;
}

- (HCSStarRatingView *)starRatingView {

    if (_starRatingView == nil) {
        _starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectZero];
        _starRatingView.maximumValue = 5;
        _starRatingView.minimumValue = 0;
        _starRatingView.spacing = 2.5;
        _starRatingView.allowsHalfStars = YES;
        _starRatingView.accurateHalfStars = YES;
        _starRatingView.tintColor = UIColorFromRGB(0xF08F4D, 1);
        _starRatingView.userInteractionEnabled = NO;
    }
    
    return _starRatingView;
}

- (UILabel *)infoLabel {
    
    if (_infoLabel == nil) {
        _infoLabel = [[UILabel alloc] init];
        _infoLabel.textColor = UIColorFromRGB(0x999999, 1);
        _infoLabel.font = [UIFont systemFontOfSize:13];
        _infoLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _infoLabel;
}

- (UIView *)collectView {
    
    if (_collectView == nil) {
        _collectView = [[UIView alloc] init];
        _collectView.backgroundColor = UIColorFromRGB(0x33a928, 1);
        _collectView.layer.masksToBounds = YES;
        _collectView.layer.cornerRadius = 15/2.0;
    }
    
    return _collectView;
}

- (UIImageView *)collectImage {

    if (_collectImage == nil) {
        _collectImage = [[UIImageView alloc] init];
        _collectImage.image = [UIImage imageNamed:@"lz_home_collect"];
    }
    return _collectImage;
}

- (UILabel *)collectNum {

    if (_collectNum == nil) {
        _collectNum = [[UILabel alloc] init];
        _collectNum.textColor = UIColorFromRGB(0xffffff, 1);
        _collectNum.font = [UIFont systemFontOfSize:10];
        _collectNum.text = @"0";
    }
    return _collectNum;
}

- (UIView *)commentView {
    
    if (_commentView == nil) {
        _commentView = [[UIView alloc] init];
        _commentView.backgroundColor = UIColorFromRGB(0x33a928, 1);
        _commentView.layer.masksToBounds = YES;
        _commentView.layer.cornerRadius = 15/2.0;
    }
    
    return _commentView;
}

- (UIImageView *)commentImage {
    
    if (_commentImage == nil) {
        _commentImage = [[UIImageView alloc] init];
        _commentImage.image = [UIImage imageNamed:@"lz_home_comment"];
    }
    return _commentImage;
}

- (UILabel *)commentNum {
    
    if (_commentNum == nil) {
        _commentNum = [[UILabel alloc] init];
        _commentNum.textColor = UIColorFromRGB(0xffffff, 1);
        _commentNum.font = [UIFont systemFontOfSize:10];
        _commentNum.text = @"0";
    }
    return _commentNum;
}

@end
